package gcj2013.qual;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.korifey.ffalg.NumberTheory;
import org.korifey.ffalg.Probabilities;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class B extends AbstractRunner {		
	
	static class X implements Comparable<X> {
		int i; int j; int p;

		public X(int i, int j, int p) {
			super();
			this.i = i;
			this.j = j;
			this.p = p;
		}

		@Override
		public int compareTo(X x) {
			return -(this.p - x.p);
		}
		
	}
	
	@Override
	public void handleCase(int caseNumber) throws Exception {
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		
		X[] a = new X[n*m]; 
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				a[j+m*i] = new X(i, j, scanner.nextInt());
			}
		}
		Arrays.sort(a);
		int [] nn = new int[n];
		int[] mm = new int[m];
		for (int k=0; k<a.length; k++) {
			if (nn[a[k].i] > a[k].p && mm[a[k].j] > a[k].p) {
				out.write("NO\n");
				return;
			}
			if (nn[a[k].i] <= a[k].p) {
				nn[a[k].i] = a[k].p;
			}
			if (mm[a[k].j] <= a[k].p) {
				mm[a[k].j] = a[k].p;
			}
		}
		out.write("YES\n");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new B().init(SIZE.large).execute();
	}

}
